<script>
$(document).ready(function() {

	//cap nhat ghi chú
	$('.update_note').blur(function(){
		var tmp=$(this);
		$.ajax({
			   type: 'POST',
			   url: '<?php echo $this->url(array("action"=>"ajax-update-note","module"=>"group","controller"=>"index"),null,true);?>',
			   data: 'target='+tmp.attr('id')+'&note='+tmp.val(),
			   success: function(msg){
			   }
			 });
	});

	//check chọn
	$(".row0 input[type='checkbox']").click(function()
	{	
		var checked=$(this).is(':checked'); 
		var id=$(this).closest('tr').eq(0).attr('id');
		if(id=='0')//check tất cả
		{
			$("input[type='checkbox']").attr('checked',checked);
		}
		else//check module, check controller
		{
			$("input[id^='"+id+"_']").attr('checked',checked);
		}
	});
	
});

</script>

<style>
input[type=text]
{
	background-color:transparent;
    border: 0px solid silver;
	width:100%;
}
input[type=text]:FOCUS{	
	background-color:#FFFFFF;
    border: 1px solid silver;
}
.action{}
.controller{font-size:16px;font-style: italic;}
.module{font-size:18px;font-weight: bold}
</style>

<?php $this->placeholder('toolbar')->captureStart();?>
<?php echo $this->partial('index/toolbar/apply.phtml','admin') ?>
<?php echo $this->partial('index/toolbar/save-and-close.phtml', 'admin' )?>
<?php echo $this->partial('index/toolbar/divider.phtml', 'admin') ?>
<?php echo $this->partial('index/toolbar/cancel.phtml', 'admin') ?>
<?php $this->placeholder('toolbar')->captureEnd();?> 

<form id="adminForm" name="adminForm" method="post" action="<?php echo $this->url(); ?>">	
	<input type='hidden' name='adminAction' id='adminAction' />
	<div class="clr"> </div>
	<table class="adminlist">
		<thead>
			<tr class='row0' id='0'>
				<th width="1%" ><input type='checkbox'></th>
				<th width="15%" colspan="3">Tính năng</th>
				<th>Ghi chú</th>
				<th width="200px">Đường dẫn</th>
	         </tr>
		</thead>
      	<tbody>
        <?php 
        $i=1;
        foreach ( $this->resources as $module_name => $value )
		{
		?>
			<tr class='row0' id='<?php echo $i?>'>
				<td class='center' width='1%'>
					<input type='checkbox'>
				</td>
				<td class='module' colspan='3'>
					<?php echo $value['module_order'].". ".$module_name;?>
				</td>
				<td>
					<input type='text' value='<?php echo $this->escape($value['module_note']) ?>' class='module update_note' id='module_<?php echo $value['module_id']?>' />
				</td>
				<td></td>
			</tr>
		<?php 
			$j=1;
			foreach ( $value ['controllers'] as $controller_name => $value2 )
			{
		?>
			<tr class='row0' id='<?php echo $i?>_<?php echo $j?>'>
				<td></td>
				<td class='center' width='1%'>
					<input type='checkbox' id='<?php echo $i?>_<?php echo $j?>'>
				</td>
				<td class='controller'  colspan='2'>
					<?php echo $value2['controller_order'].". ".$controller_name;?>
				</td>
				<td>
					<input type='text' value='<?php echo $this->escape($value2['controller_note']) ?>' class='controller update_note' id='controller_<?php echo $value2['controller_id']?>' />
				</td>
				<td></td>
			</tr>
		<?php 
				$k=1;
				foreach ( $value2 ['actions'] as $action_name => $value3 )
				{
        ?>
        	<tr id='row_action' class='row0' style='font-size:12px'>
	            <td colspan='2'></td>
				<td class='center' width='1%' id='check_action'>
					<input type='checkbox' <?php echo $value3['checked'];?> id='<?php echo $i?>_<?php echo $j?>_<?php echo $k?>' name='group_permission[]' value='<?php echo $module_name."/".$controller_name."/".$action_name;?>'>
				</td>
	            <td class='action'>
	            	<span class='red bold'><?php echo $value3['action_order']."."?></span> <?php echo $value3['action_name'] ?>
	            </td>
	            <td >	            	
	            	<input type='text' value='<?php echo $this->escape($value3['action_note']) ?>' class='action update_note' id='action_<?php echo $value3['action_id']?>' />
	            </td>
	            <td>
	            	<?php echo $value3['action_url'] ?>
	            </td>
         	</tr>
        <?php
        			$k++;
				}
				$j++;
			}
			$i++;
        }
        ?>
		</tbody>
		<tfoot>
	        <tr>
	        	<td colspan="6">
		            <div class="container">
						
	               </div>
	            </td>
	        </tr>
      	</tfoot>
   	</table>
</form>